how to validate fields in onchange function